import { _decorator, Component, Node } from 'cc';
import { BasicUI } from '../../Init/Basic/BasicUI';
import { EventTypes } from '../../Init/Managers/EventTypes';
import { PlatformType, SDKSystem } from '../../Init/SystemSDK/SDKSystem';
import { UIEnum } from '../../Init/SystemUI/UIEnum';
import { UISystem } from '../../Init/SystemUI/UISystem';
const { ccclass, property } = _decorator;

@ccclass('CustomAdUI')
export class CustomAdUI extends BasicUI {

    hideCb = null;
    show(hideCb?) {
        this.hideCb = hideCb;
        //只对微信平台
        if (SDKSystem._curPlatform == PlatformType.WXMiniGame) {
            super.show();
            this.showCustomAd();
        } else {
            setTimeout(() => {
                UISystem.hideUI(UIEnum.CustomAdUI);
            }, 0);
        }
    }

    hide() {
        super.hide();
        this.hideCb && this.hideCb();
        this.hideCb = null;
    }

    showCustomAd() {
        this.emit(EventTypes.SDKEvents.ShowCustomAd, 0, {
            success: () => {

            }, fail: () => {
                UISystem.hideUI(UIEnum.CustomAdUI);
            }, close: () => {
                UISystem.hideUI(UIEnum.CustomAdUI);
            }
        })
    }
}

